﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _2_2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnFtoC_Click(object sender, EventArgs e)
        {
            try
            {
                double f = Convert.ToDouble(txtFahrenheit.Text);
                double c = 5.0 / 9 * (f - 32);
                txtCelsius.Text = c.ToString("F2");
            }
            catch (Exception ex)
            {
                MessageBox.Show("请输入有效的温度值！");
            }
        }

        private void btnCtoF_Click(object sender, EventArgs e)
        {
            try
            {
                double c = Convert.ToDouble(txtCelsius.Text);
                double f = (9.0 / 5 * c + 32);
                txtFahrenheit.Text = f.ToString("F2");
            }
            catch (Exception ex)
            {
                MessageBox.Show("请输入有效的温度值！");
            }
        }
    }
}
